//模块定义加载区域 ===================================================
const gulp = require('gulp');//本地gulp的模块定义

const imagemin = require('gulp-imagemin');//压缩图片

const scripts = require('./conf/index').scripts;

const scssJSON = require('./conf/index').scss

const {     
      mergeMyScripts,
      mergeMyScss,
} = require("./utils/index")
let [scriptsTaskArray,scssTaskArray] = [];

// 功能区 ===================================================

/**
 * @function init 初始化功能 , 编列了scripts路径还有创建了 scripts 指令;
 * @function watchScripts 根据scripts对象实现的 watch 监听封装
 * @function mergeMyScripts 根据scripts 对象实现的scripts指令拆分,文件合并
 * 
 */
function init(){
      scriptsTaskArray = mergeMyScripts(scripts, "scripts-build-", "build");
      scssTaskArray = mergeMyScss(scssJSON, "scss-build-", "build");
}

//指令定义区

/**
 * @task html :  转存html
 * 
 */

//获取src中所有.html文件------------start---------------
gulp.task('html-build',()=>{
      return gulp.src(['./src/*.html']).pipe(gulp.dest('./dist'));
})
//获取src中所有.html文件------------end---------------

//获取src中所有.json文件------------start---------------
gulp.task('json-build',()=>{
      return gulp.src(['./src/json/*.json']).pipe(gulp.dest('./dist/json'));
})
//获取src中所有.json文件------------end---------------

// images
gulp.task('img-build',()=>{
      return gulp.src(['./src/images/**/*.+(jpg|png)'])
      .pipe(imagemin())
      .pipe(gulp.dest('./dist/images'))
})

init();

gulp.task("scripts-build",scriptsTaskArray);
gulp.task("scss-build",scssTaskArray);

gulp.task("build",["html-build","json-build","scripts-build","scss-build","img-build"]);

